//
//  InputInfoView.swift
//  PicPost
//
//  Created by dream on 2024/1/10.
//

import UIKit
import TYAlertController
import TZImagePickerController
import MJRefresh

class InputInfoView: PrentView {
    
    @IBOutlet weak var infoView: UIView!
    
    @IBOutlet weak var headerImageView: UIImageView!
    
    @IBOutlet weak var nameField: UITextField!
    
    @IBAction func start(_ sender: UIButton) {
        let view = Bundle.main.loadNibNamed("TermsView", owner: nil)?.first as? TermsView
        guard let alertVc = TYAlertController(alert: view, preferredStyle: .actionSheet) else {return}
        getCurrentVc().present(alertVc, animated: true)
    }
    
    @IBAction func skip(_ sender: UIButton) {
        hide()
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let safeAreaInsets = UIApplication.shared.keyWindow?.rootViewController?.view.safeAreaInsets ?? .zero
        self.viewWithTag(20)?.snp.updateConstraints ({ make in
            print(make.bottom)
            make.bottom.equalTo(-20-safeAreaInsets.bottom)
        })
        
        infoView.addTapEvent {[weak self] in
            guard let self = self else {return}
            let picker = TZImagePickerController(maxImagesCount: 1, delegate: self)!
            picker.allowPickingVideo = false
            getCurrentVc().present(picker, animated: true)
        }
    }

}


extension InputInfoView: TZImagePickerControllerDelegate {
    func imagePickerController(_ picker: TZImagePickerController!, didFinishPickingPhotos photos: [UIImage]!, sourceAssets assets: [Any]!, isSelectOriginalPhoto: Bool) {
        headerImageView.image = photos.first
    }
}
